package xyz.poke.business.tool.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import xyz.poke.business.tool.exception.BusinessException;
import xyz.poke.business.tool.utils.ResponseUtils;

/**
 * @author 迫壳
 * @date 2024/3/3 21:23
 */
@Aspect
@Component
public class ExceptionHandlerAspect {

    @Pointcut(value = "execution(* xyz.poke.business.tool.controller.*.*(..))")
    public void pointCut(){

    }

    @Around("pointCut()")
    public Object doAround(ProceedingJoinPoint joinPoint) {
        try {
            return joinPoint.proceed();
        } catch (BusinessException businessException) {
            return ResponseUtils.fail(businessException.getMsg(), businessException.getErrorCode());
        } catch (Throwable e) {
            return ResponseUtils.fail("网络繁忙,请稍后重试", 500);
        }
    }

}
